<template>
  <div>
    <v-btn
      class="hxg-btn hxg-home-btn"
      :class="PosLeft ? 'left' : 'right'"
      @click="ShowMenu"
      color="primary"
    >
      <img src="../assets/icon/home.png" width="25px" alt srcset />
    </v-btn>
    <v-btn
      class="hxg-btn hxg-search-btn"
      :class="PosLeft ? 'left' : 'right'"
      color="success"
      v-if="setItems[3].active"
      @click="ShowRule"
    >
      <img src="../assets/icon/search.png" width="25px" alt srcset />
    </v-btn>
    <div v-if="isShowMenu">
      <v-sheet
        height="100vh"
        class="overflow-hidden"
        style="position: relative"
      >
        <v-navigation-drawer
          v-model="drawer"
          fixed
          temporary
          :right="PosLeft ? false : true"
        >
          <v-list-item>
            <v-list-item-avatar>
              <v-img :src="user.avatar"></v-img>
            </v-list-item-avatar>

            <v-list-item-content>
              <v-list-item-title>{{ user.nickname }}</v-list-item-title>
            </v-list-item-content>
          </v-list-item>

          <v-divider></v-divider>

          <v-list dense nav>
            <v-subheader>基础设置</v-subheader>

            <v-list-item-group v-model="model" multiple>
              <template v-for="(item, i) in setItems">
                <v-divider v-if="!item" :key="`divider-${i}`"></v-divider>
                <v-list-item
                  v-else
                  :key="`item-${i}`"
                  :value="item.name"
                  active-class="text--accent-4"
                  link
                  @click="ChangeNavItem(i)"
                >
                  <template v-slot:default="{ active }">
                    <v-list-item-content>
                      <v-list-item-title>{{ item.name }}</v-list-item-title>
                    </v-list-item-content>
                    <v-list-item-action>
                      <v-checkbox
                        :checked="active"
                        :input-value="active"
                        color="accent-4"
                      ></v-checkbox>
                    </v-list-item-action>
                  </template>
                </v-list-item>
              </template>
            </v-list-item-group>
          </v-list>
          <v-list dense nav>
            <v-subheader>高级设置</v-subheader>
            <v-list-item
              v-for="item in items"
              :key="item.title"
              link
              @click="SetEvent"
              :data-i="item.id"
            >
              <v-list-item-icon>
                <v-icon :data-i="item.id">{{ item.icon }}</v-icon>
              </v-list-item-icon>

              <v-list-item-content>
                <v-list-item-title :data-i="item.id">{{
                  item.text
                }}</v-list-item-title>
              </v-list-item-content>
            </v-list-item>
          </v-list>
          <v-list>
            <v-subheader>其他设置</v-subheader>
            <v-col
              ><v-btn
                block
                elevation="2"
                @click="ChangeNavPos"
                color="secondary"
                dark
                >滚去{{ PosLeft ? "右边" : "左边" }}</v-btn
              ></v-col
            >
            <v-col
              ><v-btn
                block
                elevation="2"
                @click="ChangeQueenType"
                dark
                :color="
                  RedQueenType == 0
                    ? 'success'
                    : RedQueenType == 1
                    ? 'warning'
                    : 'error'
                "
                >查水模式：{{
                  RedQueenType == 0
                    ? "巡查模式"
                    : RedQueenType == 1
                    ? "抄家模式"
                    : "毁灭模式"
                }}</v-btn
              ></v-col
            >
            <v-col v-show="RedQueenType != 0" class="red--text text-caption"
              >注意：为了安全起见，暂不开放此模式(还没做好)。</v-col
            >
          </v-list>
          <template v-slot:append>
            <div class="pa-2 text-center overline">吾爱小插件V1.1.0</div>
          </template>
        </v-navigation-drawer>
      </v-sheet>
    </div>
    <!-- 版规速查 -->
    <div v-if="isShowRule">
      <v-sheet
        height="100vh"
        class="overflow-hidden"
        style="position: relative"
      >
        <v-navigation-drawer
          v-model="drawer2"
          fixed
          :right="PosLeft ? false : true"
          temporary
          width="350px"
        >
          <v-text-field
            v-model="RuleKeyWords"
            filled
            label="关键词"
            clearable
          ></v-text-field>
          <template v-if="RuleList.length > 0">
            <v-card
              class="mx-auto my-2"
              width="90%"
              outlined
              tile
              v-for="(item, i) in RuleList"
              :key="i"
            >
              <v-card-text>
                <div class="red--text text-subtitle-2 font-weight-bold">
                  {{ item.rule_title }}
                </div>
                <template v-if="item.rule_detail != '-'">
                  <div class="blue--text">详情：</div>
                  <div class="text-caption" v-html="item.rule_detail"></div>
                </template>
              </v-card-text>
              <v-divider></v-divider>
              <v-card-actions class="d-flex justify-end">
                <v-btn
                  text
                  x-small
                  color="deep-blue accent-4"
                  :href="item.rule_link"
                  target="_blank"
                >
                  {{ item.type_name }}
                </v-btn>
              </v-card-actions>
            </v-card>
          </template>
          <template v-else>
            <div class="pa-2 text-center overline">——版规速查V0.2.1——</div>
          </template>
        </v-navigation-drawer>
      </v-sheet>
    </div>
    <!-- 导航设置 -->
    <v-dialog v-model="isShowTopMenuSet" max-width="500">
      <v-card class="mx-auto">
        <v-card-title>导航显示设置</v-card-title>
        <v-card-subtitle
          >点击切换显示/隐藏(切换顺序也没啥用，去掉了~)</v-card-subtitle
        >
        <v-list dense>
          <v-list-item-group v-model="TopMenuModule" multiple>
            <template v-for="(item, i) in TopMenu">
              <v-divider v-if="!item" :key="`divider-${i}`"></v-divider>

              <v-list-item
                v-else
                :key="`item-${i}`"
                :value="item.name"
                active-class="text--accent-4"
                @click="ChangeTopMenu(i)"
              >
                <template v-slot:default="{ active }">
                  <v-list-item-content>
                    <v-list-item-title v-text="item.name"></v-list-item-title>
                  </v-list-item-content>

                  <v-list-item-action>
                    <v-checkbox
                      :checked="active"
                      :input-value="active"
                      color="accent-4"
                    ></v-checkbox>
                  </v-list-item-action>
                </template>
              </v-list-item>
            </template>
          </v-list-item-group>
        </v-list>
      </v-card>
    </v-dialog>
    <!-- 板块设置 -->
    <v-dialog v-model="isShowFidListSet" max-width="500">
      <v-card class="mx-auto">
        <v-card-title>板块显示设置</v-card-title>
        <v-card-subtitle
          >点击切换显示/隐藏(好像在回收站会有bug?)</v-card-subtitle
        >
        <v-list dense>
          <v-list-item-group v-model="FidListModule" multiple>
            <template v-for="(item, i) in FidList">
              <v-divider v-if="!item" :key="`divider-${i}`"></v-divider>

              <v-list-item
                v-if="i > 0"
                :key="`item-${i}`"
                :value="item.text"
                active-class="text--accent-4"
                @click="ChangeFidList(i)"
              >
                <template v-slot:default="{ active }">
                  <v-list-item-content>
                    <v-list-item-title v-text="item.text"></v-list-item-title>
                  </v-list-item-content>

                  <v-list-item-action>
                    <v-checkbox
                      :checked="active"
                      :input-value="active"
                      color="accent-4"
                    ></v-checkbox>
                  </v-list-item-action>
                </template>
              </v-list-item>
            </template>
          </v-list-item-group>
        </v-list>
      </v-card>
    </v-dialog>
    <!-- 短语设置 -->
    <div>
      <v-dialog v-model="dialog" width="65%">
        <v-alert border="left" colored-border type="info" elevation="2">
          注意：不想单独设置审核短语时，只需添加管理短语即可。如添加了审核短语，管理短语和审核短语将分开加载。
        </v-alert>
        <v-card min-height="70vh">
          <v-card-text class="pa-0">
            <v-tabs v-model="tab">
              <v-tabs-slider></v-tabs-slider>
              <v-tab>回帖快捷短语</v-tab>
              <v-tab>管理快捷短语</v-tab>
              <v-tab>审核快捷短语</v-tab>
            </v-tabs>
            <v-tabs-items v-model="tab">
              <v-tab-item>
                <v-card flat>
                  <v-card-text class="pa-0">
                    <v-data-table
                      :headers="headers"
                      :items="RuplayList"
                      class="elevation-1 card-min-height"
                      disable-sort
                    >
                      <template v-slot:top>
                        <v-toolbar flat>
                          <v-dialog v-model="addAndEdit" max-width="500px">
                            <template v-slot:activator="{ on, attrs }">
                              <v-btn
                                color="primary"
                                dark
                                class="mb-2"
                                v-bind="attrs"
                                v-on="on"
                              >
                                新增
                              </v-btn>
                            </template>
                            <v-card>
                              <v-card-title>
                                <span class="text-h5">{{ formTitle }}</span>
                              </v-card-title>

                              <v-card-text>
                                <v-container>
                                  <v-row>
                                    <v-col cols="6">
                                      <v-text-field
                                        v-model="editedItem.words"
                                        clearable
                                        label="短语标题"
                                      ></v-text-field>
                                    </v-col>
                                    <v-col cols="6">
                                      <v-select
                                        v-model="editedItem.fid"
                                        :items="FidList"
                                        label="要显示的板块id"
                                      ></v-select>
                                    </v-col>
                                    <v-col cols="12">
                                      <v-textarea
                                        v-model="editedItem.detail"
                                        label="短语内容"
                                        auto-grow
                                        clearable
                                      ></v-textarea>
                                    </v-col>
                                  </v-row>
                                </v-container>
                              </v-card-text>

                              <v-card-actions>
                                <v-spacer></v-spacer>
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="close(1)"
                                >
                                  取消
                                </v-btn>
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="save(1)"
                                >
                                  保存
                                </v-btn>
                              </v-card-actions>
                            </v-card>
                          </v-dialog>
                          <v-dialog v-model="deleteDialog" max-width="500px">
                            <v-card>
                              <v-card-title class="text-h5"
                                >是否删除此快捷短语？</v-card-title
                              >
                              <v-card-actions>
                                <v-spacer></v-spacer>
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="closeDelete(1)"
                                  >取消</v-btn
                                >
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="deleteItemConfirm(1)"
                                  >确定</v-btn
                                >
                                <v-spacer></v-spacer>
                              </v-card-actions>
                            </v-card>
                          </v-dialog>
                        </v-toolbar>
                      </template>
                      <template v-slot:[`item.actions`]="{ item }">
                        <v-icon small class="mr-2" @click="editItem(item, 1)">
                          mdi-pencil
                        </v-icon>
                        <v-icon small @click="deleteItem(item, 1)">
                          mdi-delete
                        </v-icon>
                      </template>
                      <template v-slot:no-data>
                        <v-btn color="primary" @click="initialize">
                          重新加载
                        </v-btn>
                      </template>
                    </v-data-table>
                  </v-card-text>
                </v-card>
              </v-tab-item>
              <v-tab-item>
                <v-card flat>
                  <v-card-text class="pa-0">
                    <v-data-table
                      :headers="headers"
                      :items="AdminRuplayList"
                      class="elevation-1 card-min-height"
                      disable-sort
                    >
                      <template v-slot:top>
                        <v-toolbar flat>
                          <v-dialog v-model="addAndEdit2" max-width="500px">
                            <template v-slot:activator="{ on, attrs }">
                              <v-btn
                                color="primary"
                                dark
                                class="mb-2"
                                v-bind="attrs"
                                v-on="on"
                              >
                                新增
                              </v-btn>
                            </template>
                            <v-card>
                              <v-card-title>
                                <span class="text-h5">{{ formTitle }}</span>
                              </v-card-title>

                              <v-card-text>
                                <v-container>
                                  <v-row>
                                    <v-col cols="6">
                                      <v-text-field
                                        v-model="editedItem.words"
                                        clearable
                                        label="短语标题"
                                      ></v-text-field>
                                    </v-col>
                                    <v-col cols="6">
                                      <v-select
                                        v-model="editedItem.fid"
                                        :items="FidList"
                                        label="要显示的板块id"
                                      ></v-select>
                                    </v-col>
                                    <v-col cols="12">
                                      <v-textarea
                                        v-model="editedItem.detail"
                                        label="短语内容"
                                        auto-grow
                                        clearable
                                      ></v-textarea>
                                    </v-col>
                                  </v-row>
                                </v-container>
                              </v-card-text>

                              <v-card-actions>
                                <v-spacer></v-spacer>
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="close(2)"
                                >
                                  取消
                                </v-btn>
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="save(2)"
                                >
                                  保存
                                </v-btn>
                              </v-card-actions>
                            </v-card>
                          </v-dialog>
                          <v-dialog v-model="deleteDialog2" max-width="500px">
                            <v-card>
                              <v-card-title class="text-h5"
                                >是否删除此快捷短语？</v-card-title
                              >
                              <v-card-actions>
                                <v-spacer></v-spacer>
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="closeDelete(2)"
                                  >取消</v-btn
                                >
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="deleteItemConfirm(2)"
                                  >确定</v-btn
                                >
                                <v-spacer></v-spacer>
                              </v-card-actions>
                            </v-card>
                          </v-dialog>
                        </v-toolbar>
                      </template>
                      <template v-slot:[`item.actions`]="{ item }">
                        <v-icon small class="mr-2" @click="editItem(item, 2)">
                          mdi-pencil
                        </v-icon>
                        <v-icon small @click="deleteItem(item, 2)">
                          mdi-delete
                        </v-icon>
                      </template>
                      <template v-slot:no-data>
                        <v-btn color="primary" @click="initialize">
                          重新加载
                        </v-btn>
                      </template>
                    </v-data-table>
                  </v-card-text>
                </v-card>
              </v-tab-item>
              <v-tab-item>
                <v-card flat>
                  <v-card-text class="pa-0">
                    <v-data-table
                      :headers="headers"
                      :items="EXRuplayList"
                      class="elevation-1 card-min-height"
                      disable-sort
                    >
                      <template v-slot:top>
                        <v-toolbar flat>
                          <v-dialog v-model="addAndEdit3" max-width="500px">
                            <template v-slot:activator="{ on, attrs }">
                              <v-btn
                                color="primary"
                                dark
                                class="mb-2"
                                v-bind="attrs"
                                v-on="on"
                              >
                                新增
                              </v-btn>
                            </template>
                            <v-card>
                              <v-card-title>
                                <span class="text-h5">{{ formTitle }}</span>
                              </v-card-title>

                              <v-card-text>
                                <v-container>
                                  <v-row>
                                    <v-col cols="6">
                                      <v-text-field
                                        v-model="editedItem.words"
                                        clearable
                                        label="短语标题"
                                      ></v-text-field>
                                    </v-col>
                                    <v-col cols="6">
                                      <v-select
                                        v-model="editedItem.fid"
                                        :items="FidList"
                                        label="要显示的板块id"
                                      ></v-select>
                                    </v-col>
                                    <v-col cols="12">
                                      <v-textarea
                                        v-model="editedItem.detail"
                                        label="短语内容"
                                        auto-grow
                                        clearable
                                      ></v-textarea>
                                    </v-col>
                                  </v-row>
                                </v-container>
                              </v-card-text>

                              <v-card-actions>
                                <v-spacer></v-spacer>
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="close(3)"
                                >
                                  取消
                                </v-btn>
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="save(3)"
                                >
                                  保存
                                </v-btn>
                              </v-card-actions>
                            </v-card>
                          </v-dialog>
                          <v-dialog v-model="deleteDialog3" max-width="500px">
                            <v-card>
                              <v-card-title class="text-h5"
                                >是否删除此快捷短语？</v-card-title
                              >
                              <v-card-actions>
                                <v-spacer></v-spacer>
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="closeDelete(3)"
                                  >取消</v-btn
                                >
                                <v-btn
                                  color="blue darken-1"
                                  text
                                  @click="deleteItemConfirm(3)"
                                  >确定</v-btn
                                >
                                <v-spacer></v-spacer>
                              </v-card-actions>
                            </v-card>
                          </v-dialog>
                        </v-toolbar>
                      </template>
                      <template v-slot:[`item.actions`]="{ item }">
                        <v-icon small class="mr-2" @click="editItem(item, 3)">
                          mdi-pencil
                        </v-icon>
                        <v-icon small @click="deleteItem(item, 3)">
                          mdi-delete
                        </v-icon>
                      </template>
                      <template v-slot:no-data>
                        <v-btn color="primary" @click="initialize">
                          重新加载
                        </v-btn>
                      </template>
                    </v-data-table>
                  </v-card-text>
                </v-card>
              </v-tab-item>
            </v-tabs-items>
          </v-card-text>
          <v-divider></v-divider>
          <v-card-actions>
            <v-spacer></v-spacer>
            <v-btn color="success" @click="GetNetCB()">添加网络短语</v-btn>
            <v-btn color="primary" @click="dialog = false">完成</v-btn>
          </v-card-actions>
        </v-card>
      </v-dialog>
    </div>
    <!-- 数据导入 -->
    <v-dialog v-model="dataImportDialog" width="65%">
      <v-card class="mx-auto">
        <v-card-title>配置导入/导出</v-card-title>
        <v-card-subtitle>请不要直接修改配置信息，以防出错。</v-card-subtitle>
        <v-textarea
          filled
          name="input-7-4"
          label=""
          rows="8"
          v-model="DataTextArea"
          style="font-size: 12px"
        ></v-textarea>
        <v-card-actions>
          <v-btn color="teal" dark @click="ImportData()">导入配置</v-btn>
          <v-btn color="primary" dark @click="ExportData()">导出配置</v-btn>
          <v-btn color="error" dark @click="isSureClear = true">清空配置</v-btn>
          <!-- <button id="ExportBtn" :data-clipboard-text="DataTextArea" >导出配置</button> -->
        </v-card-actions>
      </v-card>
    </v-dialog>
    <!-- 二次确认 -->
    <v-dialog v-model="isSureClear" persistent max-width="290">
      <v-card>
        <v-card-title>清空配置</v-card-title>
        <v-card-text
          >此操作将清空缓存信息，请确认已备份数据，是否清除？</v-card-text
        >
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn color="" text @click="isSureClear = false"> 取消 </v-btn>
          <v-btn color="red darken-1" text @click="clearData()"> 确定 </v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>
    <!-- 网络短语导入 -->
    <v-dialog v-model="ShowNetCBlist" width="65%">
      <v-card class="mx-auto">
        <v-card-title
          ><v-text-field
            v-model="NetCBSearch"
            append-icon="mdi-magnify"
            label="搜索"
            single-line
            hide-details
          ></v-text-field
        ></v-card-title>
        <v-data-table
          :headers="NetCBHeaders"
          :items="NetCBList"
          :search="NetCBSearch"
          class="elevation-1 card-min-height"
          disable-sort
        >
          <template v-slot:[`item.type`]="{ item }">
            <span>{{ ["回帖短语", "管理短语", "审核短语"][item.type] }}</span>
          </template>
          <template v-slot:[`item.actions`]="{ item }">
            <v-btn color="primary" dark @click="AddNetCBData(item)">添加</v-btn>
          </template>
          <template v-slot:no-data>
            <v-btn color="primary" @click="initialize"> 重新加载 </v-btn>
          </template>
        </v-data-table>
      </v-card>
    </v-dialog>
    <!-- 消息框 -->
    <v-snackbar
      v-model="snackbar"
      :color="snackbar_color"
      top
      centered
      timeout="1500"
    >
      {{ snackbar_text }}
    </v-snackbar>
  </div>
</template>

<script>
import $ from "jquery";
export default {
  data() {
    return {
      PosLeft: true,
      tab: null,
      dialog: false,
      isShowMenu: false,
      isSureClear: false,
      ShowNetCBlist: false,
      drawer: null,
      NetCBSearch: null,
      setItems: [
        { name: "隐藏置顶", active: false },
        { name: "隐藏版规", active: false },
        { name: "快捷回复", active: false },
        { name: "版规速查", active: false },
        { name: "夜深人静", active: false },
      ],
      model: [],
      selectedItem: 1,
      DataTextArea: "",
      items: [
        { id: 1, text: "导航设置", icon: "mdi-menu" },
        { id: 2, text: "板块设置", icon: "mdi-table-column" },
        { id: 3, text: "短语设置", icon: "mdi-message-outline" },
        { id: 4, text: "配置管理", icon: "mdi-call-split" },
      ],
      user: {
        avatar: "https://avatar.52pojie.cn/images/noavatar_small.gif",
        nickname: "插件用户 0x0001",
      },
      addAndEdit: false,
      addAndEdit2: false,
      addAndEdit3: false,
      deleteDialog: false,
      deleteDialog2: false,
      deleteDialog3: false,
      headers: [
        {
          text: "短语标题",
          align: "start",
          value: "words",
        },
        {
          text: "短语内容",
          value: "detail",
          cellClass: "text-no-wrap text-truncate cell-width",
          width: "300px",
        },
        { text: "要显示的板块id", value: "fid" },
        { text: "编辑", value: "actions" },
      ],
      NetCBHeaders: [
        {
          text: "短语标题",
          align: "start",
          value: "words",
        },
        {
          text: "短语内容",
          value: "detail",
          cellClass: "text-no-wrap text-truncate cell-width",
          width: "300px",
        },
        { text: "要显示的板块id", value: "fid", filterable: false },
        { text: "短语分类", value: "type", filterable: false },
        { text: "编辑", value: "actions", filterable: false },
      ],
      RuplayList: [
        {
          words: "快捷短语",
          detail: "",
          fid: 0,
        },
      ],
      AdminRuplayList: [
        {
          words: "快捷短语",
          detail: "",
          fid: 0,
        },
      ],
      EXRuplayList: [
        {
          words: "快捷短语",
          detail: "",
          fid: 0,
        },
      ],
      editedIndex: -1,
      editedItem: {
        words: "快捷短语",
        detail: "",
        fid: 0,
      },
      defaultItem: {
        words: "快捷短语",
        detail: "",
        fid: 0,
      },
      fid: null,
      tid: null,
      isShowFidListSet: false,
      FidList: [
        { value: 0, text: "所有板块", active: true },
        { value: 2, text: "原创发布区", active: true },
        { value: 10, text: "水漫金山", active: true },
        { value: 13, text: "站点公告", active: true },
        { value: 32, text: "病毒分析区", active: true },
        { value: 5, text: "脱壳破解区", active: true },
        { value: 39, text: "招聘求职", active: true },
        { value: 40, text: "病毒样本区", active: true },
        { value: 62, text: "周边活动作品区", active: true },
        { value: 25, text: "申请专区", active: true },
        { value: 42, text: "电子书策划制作区", active: true },
        { value: 50, text: "病毒救援区", active: true },
        { value: 65, text: "移动安全区", active: true },
        { value: 66, text: "福利经验", active: true },
        { value: 41, text: "安全工具区", active: true },
        { value: 59, text: "软件调试区", active: true },
        { value: 72, text: "站务处理", active: true },
        { value: 24, text: "编程语言区", active: true },
        { value: 67, text: "2014CrackMe大赛", active: true },
        { value: 6, text: "动画发布区", active: true },
        { value: 48, text: "高级会员区", active: true },
        { value: 71, text: "吾爱破解2016安全挑战赛", active: true },
        { value: 4, text: "逆向资源区", active: true },
        { value: 77, text: "腾讯游戏安全技术竞赛", active: true },
        { value: 16, text: "精品软件区", active: true },
        { value: 8, text: "悬赏问答区", active: true },
        { value: 14, text: "回收站", active: true },
        { value: 51, text: "恶意网址区", active: true },
        { value: 74, text: "编程语言讨论求助区", active: true },
        { value: 75, text: "脱壳破解讨论求助区", active: true },
        { value: 80, text: "吾爱破解2019征文大赛投稿区", active: true },
        { value: 15, text: "投诉举报区", active: true },
        { value: 21, text: "动画精品转载区", active: true },
        { value: 22, text: "CM区", active: true },
        { value: 37, text: "电子书屋", active: true },
        { value: 73, text: "移动安全讨论求助区", active: true },
        { value: 23, text: "办公区", active: true },
        { value: 68, text: "教学培训区", active: true },
        { value: 69, text: "Android CM区", active: true },
        { value: 76, text: "往届吾爱破解动画大赛", active: true },
        { value: 34, text: "证据区", active: true },
      ],
      FidListModule: [],
      isShowTopMenuSet: false,
      TopMenu: [
        { name: "门户", id: "#mn_portal", active: true },
        { name: "网站", id: "#mn_forum", active: true },
        { name: "新帖", id: "#mn_Na063", active: true },
        { name: "搜索", id: "#mn_Ne008", active: true },
        { name: "专辑", id: "#mn_forum_11", active: true },
        { name: "家园", id: "#mn_home_4", active: true },
        { name: "悬赏", id: "#mn_N99ef", active: true },
        { name: "排行榜", id: "#mn_N12a7", active: true },
        { name: "总版规", id: "#mn_N05be", active: true },
        { name: "投诉举报", id: "#mn_N34c9", active: true },
        { name: "爱盘", id: "#mn_Na678", active: true },
        { name: "管理", id: "#mn_Ndb2c", active: true },
        { name: "帮助", id: "#mn_N0a2c", active: true },
        { name: "快捷导航", id: "#qmenu", active: true },
      ],
      TopMenuModule: [],
      snackbar: false,
      snackbar_text: "",
      snackbar_color: "success",
      LOGGER: {
        Danger: function(w) {
          console.log(
            "%c" + new Date().toLocaleTimeString() + ": " + w,
            "color:#F56C6C"
          );
        },
        Success: function(w) {
          console.log(
            "%c" + new Date().toLocaleTimeString() + ": " + w,
            "color:#67C23A"
          );
        },
        Primary: function(w) {
          console.log(
            "%c" + new Date().toLocaleTimeString() + ": " + w,
            "color:#409EFF"
          );
        },
        Warning: function(w) {
          console.log(
            "%c" + new Date().toLocaleTimeString() + ": " + w,
            "color:#E6A23C"
          );
        },
        Info: function(w) {
          console.log(
            "%c" + new Date().toLocaleTimeString() + ": " + w,
            "color:#909399"
          );
        },
      },
      isShowRule: false,
      drawer2: false,
      RuleKeyWords: "",
      RuleList: [],
      oSearch: null,
      RedQueenConfig: null,
      RedQueenType: 0,
      dataImportDialog: false,
      NetCBList: [],
    };
  },
  computed: {
    formTitle() {
      return this.editedIndex === -1 ? "新增" : "编辑";
    },
  },
  methods: {
    SetEvent: function(e) {
      let EventId = e.currentTarget.dataset.i;
      switch (EventId) {
        case "1":
          this.ShowMenu();
          setTimeout(() => {
            this.isShowTopMenuSet = true;
          }, 210);
          break;
        case "2":
          this.ShowMenu();
          setTimeout(() => {
            this.isShowFidListSet = true;
          }, 210);
          break;
        case "3":
          this.ShowMenu();
          setTimeout(() => {
            this.dialog = true;
          }, 210);
          break;
        case "4":
          this.ShowMenu();
          setTimeout(() => {
            this.dataImportDialog = true;
          }, 210);
          break;
        default:
          break;
      }
    },
    ShowMenu: function() {
      if (this.isShowMenu == false) {
        this.isShowMenu = true;
        setTimeout(() => {
          this.drawer = true;
        }, 50);
      } else {
        this.drawer = false;
        setTimeout(() => {
          this.isShowMenu = false;
        }, 200);
      }
    },
    ShowRule: function() {
      if (this.isShowRule == false) {
        this.isShowRule = true;
        setTimeout(() => {
          this.drawer2 = true;
        }, 50);
      } else {
        this.drawer2 = false;
        setTimeout(() => {
          this.isShowRule = false;
        }, 200);
      }
    },
    editItem(item, i) {
      if (i == 1) {
        this.editedIndex = this.RuplayList.indexOf(item);
        this.editedItem = Object.assign({}, item);
        this.addAndEdit = true;
      } else if (i == 2) {
        this.editedIndex = this.AdminRuplayList.indexOf(item);
        this.editedItem = Object.assign({}, item);
        this.addAndEdit2 = true;
      } else {
        this.editedIndex = this.EXRuplayList.indexOf(item);
        this.editedItem = Object.assign({}, item);
        this.addAndEdit3 = true;
      }
    },
    deleteItem(item, i) {
      if (i == 1) {
        this.editedIndex = this.RuplayList.indexOf(item);
        this.editedItem = Object.assign({}, item);
        this.deleteDialog = true;
      } else if (i == 2) {
        this.editedIndex = this.AdminRuplayList.indexOf(item);
        this.editedItem = Object.assign({}, item);
        this.deleteDialog2 = true;
      } else {
        this.editedIndex = this.EXRuplayList.indexOf(item);
        this.editedItem = Object.assign({}, item);
        this.deleteDialog3 = true;
      }
    },
    deleteItemConfirm(i) {
      let HXG_DATA = JSON.parse(localStorage.getItem("HXG_DATA")) || {};
      switch (i) {
        case 1:
          this.RuplayList.splice(this.editedIndex, 1);
          HXG_DATA.RUPLAYLIST = this.RuplayList;
          break;
        case 2:
          this.AdminRuplayList.splice(this.editedIndex, 1);
          HXG_DATA.ADMINRUPLAYLIST = this.AdminRuplayList;
          break;
        case 3:
          this.EXRuplayList.splice(this.editedIndex, 1);
          HXG_DATA.EXRUPLAYLIST = this.EXRuplayList;
          break;
        default:
          break;
      }
      localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
      this.snackbar = true;
      this.snackbar_color = "success";
      this.snackbar_text = "删除成功";
      this.closeDelete(i);
    },
    close(i) {
      if (i == 1) {
        this.addAndEdit = false;
      } else if (i == 2) {
        this.addAndEdit2 = false;
      } else {
        this.addAndEdit3 = false;
      }
      this.$nextTick(() => {
        this.editedItem = Object.assign({}, this.defaultItem);
        this.editedIndex = -1;
      });
    },
    closeDelete(i) {
      if (i == 1) {
        this.deleteDialog = false;
      } else if (i == 2) {
        this.deleteDialog2 = false;
      } else {
        this.deleteDialog3 = false;
      }

      this.$nextTick(() => {
        this.editedItem = Object.assign({}, this.defaultItem);
        this.editedIndex = -1;
      });
    },
    save(i) {
      let HXG_DATA = JSON.parse(localStorage.getItem("HXG_DATA")) || {};
      if (i == 1) {
        if (this.editedIndex > -1) {
          Object.assign(this.RuplayList[this.editedIndex], this.editedItem);
        } else {
          this.RuplayList.push(this.editedItem);
        }
        HXG_DATA.RUPLAYLIST = this.RuplayList;
        localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
      } else if (i == 2) {
        if (this.editedIndex > -1) {
          Object.assign(
            this.AdminRuplayList[this.editedIndex],
            this.editedItem
          );
        } else {
          this.AdminRuplayList.push(this.editedItem);
        }
        HXG_DATA.ADMINRUPLAYLIST = this.AdminRuplayList;
        localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
      } else {
        if (this.editedIndex > -1) {
          Object.assign(this.EXRuplayList[this.editedIndex], this.editedItem);
        } else {
          this.EXRuplayList.push(this.editedItem);
        }
        HXG_DATA.EXRUPLAYLIST = this.EXRuplayList;
        localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
      }
      this.snackbar = true;
      this.snackbar_color = "success";
      this.snackbar_text = "保存成功";
      this.close(i);
    },
    AddNetCBData: function(item) {
      this.editedItem = {
        words: item.words,
        detail: item.detail,
        fid: item.fid,
      };
      this.save(item.type + 1);
    },
    ChangeNavItem: function(i) {
      this.setItems[i].active = !this.setItems[i].active;
      if (this.setItems[i].active) {
        this.LOGGER.Success(`打开: ${this.setItems[i].name}`);
      } else {
        this.LOGGER.Warning(`关闭: ${this.setItems[i].name}`);
      }
      this.UpdateStates();
    },
    ChangeTopMenu: function(i) {
      this.TopMenu[i].active = !this.TopMenu[i].active;
      if (this.TopMenu[i].active) {
        this.LOGGER.Success(`显示: ${this.TopMenu[i].name}`);
      } else {
        this.LOGGER.Warning(`隐藏: ${this.TopMenu[i].name}`);
      }
      this.ChangeMenuEvent();
    },
    ChangeFidList: function(i) {
      this.FidList[i].active = !this.FidList[i].active;
      if (this.FidList[i].active) {
        this.LOGGER.Success(`显示: ${this.FidList[i].text}`);
      } else {
        this.LOGGER.Warning(`隐藏: ${this.FidList[i].text}`);
      }
      this.ChangeFidEvent();
    },
    // 更新页面状态
    UpdateStates: function() {
      // 置顶内容
      if (this.setItems[0].active) {
        $('tbody[id^="stickthread"]').hide();
      } else {
        $('tbody[id^="stickthread"]').show();
      }
      // 版块顶部版规
      if (this.setItems[1].active) {
        $(".bm_c.cl.pbn").hide();
      } else {
        $(".bm_c.cl.pbn").show();
      }
      // 快捷回复
      if (this.setItems[2].active) {
        $("#ShortcutPhrase").show();
      } else {
        $("#ShortcutPhrase").hide();
      }
      // 版规速查
      if (this.setItems[3].active) {
        $("._rule_div").show();
      } else {
        $("._rule_div").hide();
      }
      // 黑夜模式
      if (this.setItems[4].active) {
        // let _dark_style_ = document.createElement("link");
        // _dark_style_.href = "https://www.lingmx.com/52pj/_dark-kaifa.css";
        // _dark_style_.rel = "stylesheet";
        // _dark_style_.type = "text/css";
        // _dark_style_.id = "hxg_dark_css";
        // $("head").append(_dark_style_);
        $("html").attr("id", "DarkMode");
        this.$vuetify.theme.dark = true;
      } else {
        $("html").removeAttr("id");
        this.$vuetify.theme.dark = false;
        // let darkcss = document.getElementById("hxg_dark_css");
        // if (darkcss) {
        //   document.head.removeChild(darkcss);
        // }
      }
      let HXG_DATA = JSON.parse(localStorage.getItem("HXG_DATA")) || {};
      HXG_DATA.SETITEMS = this.setItems;
      localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
    },
    LoadFastReply: function() {
      // 载入普通快捷回复
      try {
        let SelectObj = `<select name="ShortcutPhrase" id="ShortcutPhrase" class="ShortcutPhrase">`;
        let SelectArr = new Array();
        for (let i = 0; i < this.RuplayList.length; i++) {
          if (
            this.RuplayList[i].fid == this.fid ||
            this.RuplayList[i].fid == 0
          ) {
            SelectObj += `<option value="${this.RuplayList[i].value}">${this.RuplayList[i].words}</option>`;
            SelectArr.push(this.RuplayList[i]);
          }
        }
        SelectObj += "</select>";
        $("#fastpostat").after(SelectObj);
        var obj = $("#ShortcutPhrase")[0];
        obj.onchange = function() {
          var index = obj.selectedIndex;
          $("#fastpostmessage").val(SelectArr[index].detail);
          // 是否自动点击回复按钮，默认关闭，不建议使用
          // if (CONFIG.AUTOREPLY.state) {
          //     $('#fastpostsubmit')[0].click();
          // }
        };
        this.LOGGER.Success("快捷回复加载成功");
      } catch (error) {
        this.LOGGER.Danger("快捷回复加载失败，当前页面无回复窗口");
      }

      let that = this;
      // 载入主题处理快捷回复
      $("#modmenu>a,#mdly .c a").on({
        click: function() {
          if (
            $(this).html() == "删除主题" ||
            $(this).html() == "警告" ||
            $(this).html() == "关闭" ||
            $(this).html() == "删除" ||
            $(this).html() == "屏蔽" ||
            $(this).html() == "已处理" ||
            $(this).html() == "已答复"
          ) {
            setTimeout(() => {
              try {
                // 获取违规记录 cv RS水果
                if ($("#fwin_mods .tplw div")) {
                  let thisPid = $("#fwin_mods .tplw input").val();
                  console.log(thisPid);
                  let thisUrl = $(`#favatar${thisPid} .avatar a`)[0];
                  thisUrl = thisUrl.getAttribute('href');
                  let thisUid = thisUrl.match(/uid=(\d+)/)[1];
                  if (thisUid) {
                    let userInfoUrl = `https://www.52pojie.cn/home.php?mod=space&uid=${thisUid}&do=profile&from=space`;
                    fetch(userInfoUrl)
                      .then((res) => res.blob())
                      .then((data) => {
                        // 核心 对数据重新编码 否则网页会乱码
                        const reader = new FileReader();
                        reader.readAsText(data, "gbk");
                        reader.onload = () => {
                          const parser = new DOMParser();
                          const pageHtml = parser.parseFromString(
                            reader.result,
                            "text/html"
                          );
                          $("#fwin_mods .tpclg h4").css("width", "100%");
                          $("#reason").css("width", "580px");
                          $("#reason").css("height", "50px");
                          $("#floatlayout_topicadmin").after(pageHtml.querySelector('#pcr'));
                        };
                      });
                  } else {
                    that.LOGGER.Danger("未匹配到uid");
                  }
                }
                if (!document.querySelector("#ShortcutPhrase")) {
                  let SelectObj = `<select name="ShortcutPhrase" id="ShortcutPhrase" class="ShortcutPhrase" style="float:none">`;
                  let SelectArr = new Array();
                  for (let i = 0; i < that.AdminRuplayList.length; i++) {
                    if (
                      that.AdminRuplayList[i].fid == that.fid ||
                      that.AdminRuplayList[i].fid == 0
                    ) {
                      SelectObj += `<option value="${that.AdminRuplayList[i].value}">${that.AdminRuplayList[i].words}</option>`;
                      SelectArr.push(that.AdminRuplayList[i]);
                    }
                  }
                  SelectObj += "</select>";
                  $("#fwin_mods .tpclg .dpbtn").after(SelectObj);
                  $("#fwin_mods .tpclg .dpbtn").css("float", "none");
                  $("#fwin_mods .tpclg h4").css("display", "flex");
                  $("#fwin_mods .tpclg h4").css("align-items", "center");
                  $("#fwin_mods .tpclg h4").css(
                    "justify-content",
                    "space-between"
                  );
                  $("#fwin_mods .tpclg h4").css(
                    "flex-direction",
                    "row-reverse"
                  );
                  $("#fwin_mods .tpclg h4").removeClass("cl");
                  var obj = $("#ShortcutPhrase")[0];
                  obj.onchange = function() {
                    var index = obj.selectedIndex;
                    $("#reason").val(SelectArr[index].detail);
                  };
                  that.LOGGER.Success("管理快捷回复加载成功");
                } else {
                  that.LOGGER.Success("管理快捷回复已载入");
                }
              } catch (error) {
                that.LOGGER.Danger("管理快捷回复加载失败，当前页面无回复窗口");
              }
            }, 500);
          }
        },
      });

      // 载入审核快捷回复
      $("#moderate span.y>a,.um.bw0.cl button:nth-child(3)").on({
        click: function() {
          if ($(this).html() != "查看" || $(this).html() != "展开") {
            setTimeout(() => {
              try {
                if (!document.querySelector("#ShortcutPhrase")) {
                  let SelectObj = `<select name="ShortcutPhrase" id="ShortcutPhrase" class="ShortcutPhrase" style="float:none">`;
                  let SelectArr = new Array();

                  if (that.EXRuplayList.length <= 1) {
                    for (let i = 0; i < that.AdminRuplayList.length; i++) {
                      if (
                        that.AdminRuplayList[i].fid == that.fid.value ||
                        that.AdminRuplayList[i].fid == 0
                      ) {
                        SelectObj += `<option value="${that.AdminRuplayList[i].value}">${that.AdminRuplayList[i].words}</option>`;
                        SelectArr.push(that.AdminRuplayList[i]);
                      }
                    }
                  } else {
                    for (let i = 0; i < that.EXRuplayList.length; i++) {
                      if (
                        that.EXRuplayList[i].fid == that.fid.value ||
                        that.EXRuplayList[i].fid == 0
                      ) {
                        SelectObj += `<option value="${that.EXRuplayList[i].value}">${that.EXRuplayList[i].words}</option>`;
                        SelectArr.push(that.EXRuplayList[i]);
                      }
                    }
                  }
                  SelectObj += "</select>";
                  $("#fwin_mods .dpbtn").before(SelectObj);
                  var obj = $("#ShortcutPhrase")[0];
                  obj.onchange = function() {
                    var index = obj.selectedIndex;
                    $("#reason").val(SelectArr[index].detail);
                  };
                  that.LOGGER.Success("管理快捷回复加载成功");
                } else {
                  that.LOGGER.Success("管理快捷回复已载入");
                }
              } catch (error) {
                that.LOGGER.Danger("管理快捷回复加载失败，当前页面无回复窗口");
              }
            }, 500);
          }
        },
      });
    },
    // 载入站务区一键评分
    LoadScoringBtn: function() {
      try {
        let _TabList_ = $('table[id^="pid"]');
        for (let i = 0; i < _TabList_.length; i++) {
          let _Parent_ = _TabList_[i].querySelector(".pob.cl> p");
          // let _ANode_ = _TabList_[i].querySelector('.pob.cl> p a');
          let Nhtml = null;
          let Nhtml2 = null;
          if (this.fid == 72 || this.fid == 15) {
            Nhtml = `<a href="javascript:;" onclick="SnedScore(0,${_TabList_[i]
              .getAttribute("id")
              .slice(3)})">热心+1</a>`;
            Nhtml2 = `<a href="javascript:;" onclick="SnedScore(1,${_TabList_[i]
              .getAttribute("id")
              .slice(3)})">CB+1</a>`;
          } else if (this.fid == 22 || this.fid == 69) {
            Nhtml = `<a href="javascript:;" onclick="SnedScore(2,${_TabList_[i]
              .getAttribute("id")
              .slice(3)})">CB-8</a>`;
            Nhtml2 = `<a href="javascript:;" onclick="SnedScore(3,${_TabList_[i]
              .getAttribute("id")
              .slice(3)})">违规+1</a>`;
          }
          let tempNode = document.createElement("a");
          let tempNode2 = document.createElement("a");
          tempNode.innerHTML = Nhtml;
          tempNode2.innerHTML = Nhtml2;
          Nhtml = tempNode.firstChild;
          Nhtml2 = tempNode2.firstChild;
          _Parent_.prepend(Nhtml);
          _Parent_.prepend(Nhtml2);
        }
      } catch (error) {
        this.LOGGER.Warning(error);
      }
    },
    SnedScore: function(index, pid) {
      window.showWindow(
        "rate",
        `forum.php?mod=misc&action=rate&tid=${window.tid}&pid=${pid}`,
        "get",
        -1
      );
      setTimeout(() => {
        switch (index) {
          case 0:
            $("#score6")[0].value = "1";
            $("#reason")[0].value = "已经处理，感谢您对吾爱破解论坛的支持！";
            break;
          case 1:
            $("#score2")[0].value = "1";
            $("#reason")[0].value = "已经处理，感谢您对吾爱破解论坛的支持！";
            break;
          case 2:
            $("#score2")[0].value = "-8";
            $("#reason")[0].value = "CM区禁止灌水";
            break;
          case 3:
            $("#score2")[0].value = "-15";
            $("#score8")[0].value = "1";
            $("#reason")[0].value = "CM区禁止灌水";
            break;
          default:
            this.LOGGER.Warning("自动评分失败");
            break;
        }
      }, 500);
    },
    // 载入主题分类修改-已处理，已答复
    LoadClassifyModify: function() {
      // 已处理
      try {
        let _NavList_ = $("#modmenu");
        let html = `<a href="javascript:;">已处理</a>`;
        let tempNode = document.createElement("a");
        tempNode.innerHTML = html;
        html = tempNode.firstChild;
        html.onclick = function() {
          window.modthreads(2, "type");
          setTimeout(() => {
            if (window.fid == 72) {
              $("#typeid")[0].value = 285;
            } else if (window.fid == 15) {
              $("#typeid")[0].value = 21;
            }
            $("#reason")[0].value = "已经处理，感谢您对吾爱破解论坛的支持！";
          }, 500);
        };

        _NavList_.append(html);
        _NavList_.append(`<span class="pipe">|</span>`);
      } catch (error) {
        this.LOGGER.Warning(error);
      }

      // 已答复
      try {
        let _NavList_ = $("#modmenu");
        let html = `<a href="javascript:;">已答复</a>`;
        let tempNode = document.createElement("a");
        tempNode.innerHTML = html;
        html = tempNode.firstChild;
        html.onclick = function() {
          window.modthreads(2, "type");
          setTimeout(() => {
            if (window.fid == 72) {
              $("#typeid")[0].value = 288;
            } else if (window.fid == 15) {
              $("#typeid")[0].value = 206;
            }
            $("#reason")[0].value = "已经处理，感谢您对吾爱破解论坛的支持！";
          }, 500);
        };

        _NavList_.append(html);
      } catch (error) {
        this.LOGGER.Warning(error);
      }
    },

    // 载入查重按钮
    LoadFindRepeat: function() {
      // 主题帖查重
      try {
        let text = $("#thread_subject").prop("innerHTML");
        if ("" != text) {
          let _NavList_ = $("#modmenu");
          let temp_url =
            "https://www.baidu.com/s?wd=" + text + "%20site:www.52pojie.cn";
          let html =
            "<span class='pipe'>|</span><a href='" +
            temp_url +
            "' target='_blank'>站内标题查重</a>";
          _NavList_.append(html);
        }
      } catch (error) {
        this.LOGGER.Warning(error);
      }
    },
    // 按顶部导航配置载入导航栏
    ChangeMenuEvent: function() {
      try {
        let NewTopNav = new Array();
        // console.log(TOPMENU)
        this.TopMenu.forEach((item) => {
          let it = $(item.id)[0];
          if (!item.active) {
            it.style.display = "none";
          } else {
            it.removeAttribute("style");
          }
          NewTopNav.push(it);
        });
        $("#nv_ph #nv ul").empty();
        NewTopNav.forEach((item) => {
          $("#nv_ph #nv ul").append(item);
        });
        let HXG_DATA = JSON.parse(localStorage.getItem("HXG_DATA")) || {};
        HXG_DATA.TOPMENU = this.TopMenu;
        localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
      } catch (error) {
        this.LOGGER.Danger("导航配置载入错误！");
      }
    },
    // 按板块配置载入板块列表
    ChangeFidEvent: function() {
      try {
        // let NewTopNav = new Array();
        this.FidList.forEach((item, index) => {
          if (item.active) {
            $(`#fid_ctrl_menu ul li:nth-child(${index + 1})`).show();
            $(`#ct select#fid option:nth-child(${index + 1})`).show();
          } else {
            $(`#fid_ctrl_menu ul li:nth-child(${index + 1})`).hide();
            $(`#ct select#fid option:nth-child(${index + 1})`).hide();
          }
        });
        let HXG_DATA = JSON.parse(localStorage.getItem("HXG_DATA")) || {};
        HXG_DATA.FIDLIST = this.FidList;
        localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
      } catch (error) {
        this.LOGGER.Danger(error);
        this.LOGGER.Danger("板块配置载入错误！");
      }
    },
    GetUserInfo: function() {
      try {
        this.user.avatar = document.querySelector(".avt.y a img")
          ? document.querySelector(".avt.y a img").src
          : "https://avatar.52pojie.cn/images/noavatar_small.gif";
        this.user.nickname = document.querySelector("a[title='访问我的空间']")
          ? document.querySelector("a[title='访问我的空间']").innerHTML
          : "插件用户 0x0001";
        this.fid = window.fid;
        this.tid = window.tid;
        if (
          this.user.avatar !=
            "https://avatar.52pojie.cn/images/noavatar_small.gif" &&
          this.user.nickname != "插件用户 0x0001"
        ) {
          let HXG_DATA = JSON.parse(localStorage.getItem("HXG_DATA")) || {};
          HXG_DATA.USERINFO = new Object();
          HXG_DATA.USERINFO.AVATAR = this.user.avatar;
          HXG_DATA.USERINFO.NICKNAME = this.user.nickname;
          localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
        }
        if (this.tid) {
          this.GetConfig();
        }
        this.LoadLocalData();
      } catch (error) {
        this.LOGGER.Warning("载入数据出错，请联系开发者。");
        this.LOGGER.Warning(error);
      }
    },
    ChangeNavPos: function() {
      this.PosLeft = !this.PosLeft;
      let HXG_DATA = JSON.parse(localStorage.getItem("HXG_DATA")) || {};
      HXG_DATA.POSLEFT = this.PosLeft;
      localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
    },
    ExportData: function() {
      let HXG_DATA = btoa(encodeURI(localStorage.getItem("HXG_DATA")));
      this.DataTextArea = HXG_DATA;
      setTimeout(() => {
        let cp = $("[name='input-7-4']");
        cp.select();
        document.execCommand("copy", false, null);
        this.snackbar = true;
        this.snackbar_color = "success";
        this.snackbar_text = "已复制到剪贴板";
      }, 100);
    },
    clearData: function() {
      localStorage.clear();
      this.snackbar = true;
      this.snackbar_color = "success";
      this.snackbar_text = "清空配置完成，刷新页面后生效";
    },
    ImportData: function() {
      console.log(this.DataTextArea);
      try {
        let HXG_DATA = JSON.parse(decodeURI(atob(this.DataTextArea)));
        localStorage.setItem("HXG_DATA", JSON.stringify(HXG_DATA));
        this.snackbar = true;
        this.snackbar_color = "success";
        this.snackbar_text = "导入配置成功，刷新页面后生效";
      } catch (error) {
        console.log(error);
        this.snackbar = true;
        this.snackbar_color = "error";
        this.snackbar_text = "导入配置失败";
      }
    },
    // 加载本地配置
    LoadLocalData: function() {
      let HXG_DATA = JSON.parse(localStorage.getItem("HXG_DATA")) || null;
      try {
        if (HXG_DATA) {
          this.setItems = HXG_DATA.SETITEMS || this.setItems;
          this.setItems.forEach((item) => {
            if (item.active) {
              this.model.push(item.name);
            }
          });
          this.RuplayList = HXG_DATA.RUPLAYLIST || this.RuplayList;
          this.AdminRuplayList =
            HXG_DATA.ADMINRUPLAYLIST || this.AdminRuplayList;

          this.EXRuplayList = HXG_DATA.EXRUPLAYLIST || this.EXRuplayList;
          this.TopMenu = HXG_DATA.TOPMENU || this.TopMenu;
          this.TopMenu.forEach((item) => {
            if (item.active) {
              this.TopMenuModule.push(item.name);
            }
          });
          this.FidList = HXG_DATA.FIDLIST || this.FidList;
          this.FidList.forEach((item) => {
            if (item.active) {
              this.FidListModule.push(item.text);
            }
          });
          this.PosLeft = HXG_DATA.POSLEFT || false;
          if (HXG_DATA.USERINFO) {
            this.user.avatar = HXG_DATA.USERINFO.AVATAR;
            this.user.nickname = HXG_DATA.USERINFO.NICKNAME;
          }
        } else {
          this.LOGGER.Info("无数据");
        }
      } catch (error) {
        this.LOGGER.Warning("数据加载失败，使用默认数据");
      }
      this.LoadFastReply();
      try {
        if (
          this.fid == 72 ||
          this.fid == 15 ||
          this.fid == 22 ||
          this.fid == 69
        ) {
          // 载入评分按钮(热心+1，CB+1)
          this.LoadScoringBtn();
          if (this.fid == 72 || this.fid == 15) {
            // 载入分类按钮(一键已处理，一键已答复)
            this.LoadClassifyModify();
          }
        }
      } catch (error) {
        this.LOGGER.Info("当前不在帖子内，不加载评分按钮及分类按钮");
      }
      this.ChangeMenuEvent();
      this.ChangeFidEvent();
      this.UpdateStates();
    },
    // 一键查水系统
    StartRedQueen: function() {
      try {
        // 获取回复列表
        let hfList = document.querySelectorAll(".t_f");
        // 获取当前页码
        let NowPage = document.querySelector(".pg strong")
          ? document.querySelector(".pg strong").innerText
          : 1;
        // 匹配的列表
        // let crapList = new Array();
        hfList.forEach((item, i) => {
          // 第一页，不查第一条
          if (!(NowPage == 1 && i == 1)) {
            let reg = new RegExp(this.RedQueenConfig, "g");
            if (reg.test(item.innerText) && item.innerText.length <= 15) {
              let mid = item.id.split("_")[1];
              let Par = item.offsetParent.offsetParent;
              Par.classList.add("hxg-warning");
              let uname = Par.previousElementSibling.querySelector(".xw1")
                .innerText;
              let html = `<span class="pipe">|</span>`;
              let html2 = `<a class="hxg-warning-text" href="javascript:;" onclick="RunDeleteCrap(${mid},'${uname}')">此人疑似灌水，点击一键查水</a>`;
              let tempNode = document.createElement("div");
              let tempNode2 = document.createElement("div");
              tempNode.innerHTML = html;
              tempNode2.innerHTML = html2;
              html = tempNode.firstChild;
              html2 = tempNode2.firstChild;
              Par.querySelector(".authi").append(html);
              Par.querySelector(".authi").append(html2);
            }
          }
        });
      } catch (error) {
        this.LOGGER.Warning("一键查水系统部署失败。");
      }
    },
    ChangeQueenType: function() {
      this.RedQueenType = this.RedQueenType + 1;
      if (this.RedQueenType > 2) {
        this.RedQueenType = 0;
      }
    },
    RunDeleteCrap: function(mid, uname) {
      /**
       * 查水模式
       * 1. 巡查模式：只会删除当前回复
       * 2. 抄家模式：删除当前回复并跳转到此人回帖列表，按关键词自动删除
       * 3. 毁灭模式：删除此人全部回复
       */
      if (this.RedQueenType == 0) {
        this.PatrolMode(mid);
      } else if (this.RedQueenType == 1) {
        this.LOGGER.Warning("本模式暂不可使用，请切换查水模式");
        //  先不给用
        this.PatrolMode(mid).then(() => {
          // 打开该人回复页面
          window.open(
            "https://www.52pojie.cn/forum.php?mod=modcp&action=thread&op=post&do=search&searchsubmit=1&users=" +
              uname
          );
          // 设置关键词
          // document.getElementsByName("keywords")[1].value = "关键词";
          // 点击查找按钮
          // document.querySelector("#searchsubmit").click()
          // 查看违规回复数
          // document.querySelector(".mtm.mbm strong").innerText;
          // 全选违规回复
          // document.querySelector("#chkall").click()
          // 删除违规回复
          // document.querySelector("#deletesubmit").click()
        });
      } else {
        this.LOGGER.Warning("本模式暂不可使用，请切换查水模式");
      }
    },
    PatrolMode: function(mid) {
      return new Promise((resolve, reject) => {
        try {
          document.getElementById(`manage${mid}`).click();
          document.querySelector("#mdly .c a:nth-child(6)").click();
          setTimeout(() => {
            // 设置删帖理由
            document.querySelector("#reason").innerHTML =
              "请勿灌水，提高回帖质量是每位会员应尽的义务！";
            // 勾选违规登记
            document.querySelector("#crimerecord").click();
            // 自动点击确定 只在抄家模式和毁灭模式下启动
            this.RedQueenType == 1 &&
              document.querySelector("#modsubmit").click();
            resolve();
          }, 500);
        } catch (error) {
          this.LOGGER.Warning("查水失败了~" + JSON.stringify(error));
          reject(error);
        }
      });
    },
    // 获取灌水配置
    GetConfig: function() {
      $.ajax({
        type: "GET",
        url: "https://52pj.lingmx.com/GetConfig",
        dataType: "json",
        success: (result) => {
          if (result.code == 0) {
            this.RedQueenConfig = result.data;
            this.StartRedQueen();
          }
        },
      });
    },
    // 获取数据库短语列表
    GetNetCB: function() {
      $.ajax({
        type: "GET",
        url: "https://52pj.lingmx.com/GetCBList",
        dataType: "json",
        success: (result) => {
          if (result.code == 0) {
            this.NetCBList = result.data;
            this.ShowNetCBlist = true;
          }
        },
      });
    },
  },
  mounted() {
    window["SnedScore"] = (index, pid) => {
      this.SnedScore(index, pid);
    };
    window["RunDeleteCrap"] = (mid, uname) => {
      this.RunDeleteCrap(mid, uname);
    };
  },
  watch: {
    RuleKeyWords() {
      clearTimeout(this.ToSearch);
      this.ToSearch = setTimeout(() => {
        console.log(this.RuleKeyWords);
        let url = encodeURI(
          "https://52pj.lingmx.com/GetRulesList?keywords=" + this.RuleKeyWords
        );
        $.ajax({
          type: "GET",
          url: url,
          dataType: "json",
          success: (result) => {
            if (result.code == 0) {
              this.RuleList = result.data;
            }
            console.log(this.RuleList);
          },
        });
      }, 500);
    },
    addAndEdit(val) {
      val || this.close(1);
    },
    addAndEdit2(val) {
      val || this.close(2);
    },
    addAndEdit3(val) {
      val || this.close(3);
    },
    deleteDialog(val) {
      val || this.closeDelete(1);
    },
    deleteDialog2(val) {
      val || this.closeDelete(2);
    },
    deleteDialog3(val) {
      val || this.closeDelete(3);
    },
    drawer(val) {
      if (val == false) {
        setTimeout(() => {
          this.isShowMenu = false;
        }, 200);
      }
    },
    drawer2(val) {
      if (val == false) {
        setTimeout(() => {
          this.isShowRule = false;
        }, 200);
      }
    },
    dialog(val) {
      if (val == false) {
        this.tab = 0;
      }
    },
  },
  created() {
    // if (location.host == "www.52pojie.cn") {
    //   }
    this.GetUserInfo();
  },
};
</script>
<style scoped>
.hxg-btn {
  position: fixed;
  top: 30%;
  z-index: 9900;
  width: 50px;
  height: 40px;
  box-sizing: border-box;
  line-height: 36px;
  cursor: pointer;
  opacity: 0.5;
  transition: 0.2s;
}
.hxg-btn.left {
  left: -25px;
  padding-left: 30px !important;
  border-top-right-radius: 50px;
  border-bottom-right-radius: 50px;
}
.hxg-btn.right {
  right: -25px;
  padding-right: 30px !important;
  border-top-left-radius: 50px;
  border-bottom-left-radius: 50px;
}
.hxg-btn.left:hover {
  left: 0;
  opacity: 1;
  padding-left: 10px !important;
}
.hxg-btn.right:hover {
  right: 0;
  opacity: 1;
  padding-right: 10px !important;
}
.hxg-home-btn {
  top: 30%;
  border: 1px solid #1976d2;
  background: #1976d2 !important;
}
.hxg-search-btn {
  top: calc(30% + 50px);
  border: 1px solid #40bd17;
  background: #40bd17 !important;
}
</style>
<style>
.v-navigation-drawer--temporary {
  z-index: 9910 !important;
}
.cell-width {
  max-width: 650px !important;
}
.card-min-height {
  min-height: 570px !important;
}
/* 论坛里有container样式，防止影响 */
.v-card .container {
  border: none !important;
  margin-top: 0 !important;
  background-color: #ffffff !important;
  border-radius: 0 !important;
  position: unset;
}
</style>
